prefix =   @prefix@

CC = @CC@
LDFLAGS  = @LDFLAGS@
CPPFLAGS = @CPPFLAGS@ -I.. -I../include
BTSTACK_LIB_LDFLAGS = @BTSTACK_LIB_LDFLAGS@
BTSTACK_LIB_EXTENSION = @BTSTACK_LIB_EXTENSION@

remote_device_db_sources = @REMOTE_DEVICE_DB_SOURCES@
run_loop_sources = @RUN_LOOP_SOURCES@
springboard_access_sources = @SPRINGBOARD_ACCESS_SOURCES@
usb_sources = @USB_SOURCES@
platform_sources = @PLATFORM_SOURCES@

libBTstack_SOURCES = btstack.c hci_cmds.c linked_list.c run_loop.c $(run_loop_sources) sdp_util.c socket_connection.c utils.c
			  
BTdaemon_SOURCES =  $(libBTstack_SOURCES) \
	$(platform_sources)     \
    btstack_memory.c        \
    daemon.c                \
    hci.c                   \
    hci_dump.c              \
    hci_transport_h4.c      \
    $(usb_sources)          \
    l2cap.c                 \
    l2cap_signaling.c       \
    memory_pool.c           \
    $(remote_device_db_sources)  \
    rfcomm.c                \
    sdp.c                   \
    $(springboard_access_sources)

all: libBTstack.$(BTSTACK_LIB_EXTENSION) libBTstack.a BTdaemon

libBTstack.$(BTSTACK_LIB_EXTENSION): $(libBTstack_SOURCES)
		./get_version.sh
		$(CC) $(CPPFLAGS) $(BTSTACK_LIB_LDFLAGS) -o $@ $(libBTstack_SOURCES) $(LDFLAGS)
		@USE_LDID@ export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $@

libBTstack.a: $(libBTstack_SOURCES:.c=.o) $(libBTstack_SOURCES:.m=.o)
		ar cru $@ $(libBTstack_SOURCES:.c=.o) $(libBTstack_SOURCES:.m=.o)
		ranlib $@

BTdaemon: $(BTdaemon_SOURCES)
		$(CC) $(CPPFLAGS) -o $@ $(BTdaemon_SOURCES) $(LDFLAGS)
		@USE_LDID@ export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $@

clean:
	rm -rf libBTstack* BTdaemon *.o
	
install:    
	echo "installing BTdaemon in $(prefix)..."
	mkdir -p $(prefix)/bin $(prefix)/lib $(prefix)/include
	cp libBTstack.a libBTstack.dylib $(prefix)/lib/
	cp BTdaemon $(prefix)/bin/
	cp -r ../include/btstack $(prefix)/include
